//
//  UserSettingProfileQrcodeController.m
//  SmallElephant
//
//  Created by Faith on 2022/12/24.
//

#import "UserSettingProfileQrcodeController.h"

@interface UserSettingProfileQrcodeController ()

/// 内容视图
@property (nonatomic, strong) UIView *contentView;

/// 头像视图
@property (nonatomic, strong) UIImageView *avatarView;

/// 信息视图
@property (nonatomic, strong) UIView *infoView;

/// 昵称视图
@property (nonatomic, strong) UILabel *nicknameView;

/// ID视图
@property (nonatomic, strong) UILabel *idView;

/// 二维码视图
@property (nonatomic, strong) UIImageView *qrcodeView;

@end

@implementation UserSettingProfileQrcodeController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置标题
    [self setTitleText:@"我的二维码"];
    // 信息视图
    [self.scrollViewContent addSubview:self.contentView style:@"display: flex; flex-direction: column; border-radius: 10px; background: #FFFFFF; margin-left: 10px; margin-right: 10px; margin-top: 10px;"];
    // 加载数据
    [self loadData];
}


/// 懒加载个人资料
- (UIView *)contentView {
    if(!_contentView) {
        _contentView = [[UIView alloc] init];
        
        // 用户基本信息
        UIView *profileView = [[UIView alloc] init];
        [_contentView addSubview:profileView style:@"display: flex; flex-direction: row; padding-left: 20px;padding-right: 20px; padding-top:25px; padding-bottom: 25px;"];
        [profileView applyStyle:@"display: flex; flex-direction: row;"];
        // 添加头像视图
        [profileView addSubview:self.avatarView style:@"display: flex; width: 60px; height: 60px; border-radius: 30px; "];
        // 添加信息视图
        [profileView addSubview:self.infoView style:@"display: flex; flex:1; justify-content: center; margin-left: 12px;"];
        
        // 二维码图片
        YSQRCodeGenerator *generate = [[YSQRCodeGenerator alloc] init];
        NSString *shareUrl = [NSString stringWithFormat:@"https://www.baidu.com/"];
        generate.content = shareUrl;
        [generate setColorWithBackColor:[UIColor whiteColor] foregroundColor:[UIColor blackColor]];
        _qrcodeView = [[UIImageView alloc] initWithImage:[generate generate]];
        [_contentView addSubview:_qrcodeView style:@"display: flex; align-self: center; width: 300px; height: 300px;"];
        
        UILabel *tipsView = [[UILabel alloc] init];
        tipsView.text = @"扫一扫上面的二维码图案，加我为好友";
        [_contentView addSubview:tipsView style:@"display: flex; align-self: center; color: #888888; font-size: 14px; margin-top: 10px;"];
        
        // 按钮操作组
        UIView *operationButton = [[UIView alloc] init];
        [_contentView addSubview:operationButton style:@"display: flex; flex-direction: row; justify-content: center; align-items: center; margin-top:32px; margin-bottom: 25px;"];
        
        UIImageView *contactIconView = [[UIImageView alloc] initWithImage:[UIImage imageWithName:@"icon-download@3x"]];
        [operationButton addSubview:contactIconView style:@"display: flex; width: 18px; height: 18px;"];
        
        UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnCancel setTitle:@"长按保存图片分享给好友" forState:UIControlStateNormal];
        [operationButton addSubview:btnCancel style:@"display: flex; height: 30px; padding-left:10px; font-size: 14px; color: #338BF9;"];
        
    }
    return _contentView;
}

/// 懒加载头像视图
- (UIImageView *)avatarView {
    if(!_avatarView) {
        _avatarView = [[UIImageView alloc] init];
    }
    return _avatarView;
}

/// 懒加载用户信息视图
- (UIView *)infoView {
    if(!_infoView) {
        _infoView = [[UIView alloc] init];
        _nicknameView = [[UILabel alloc] init];
        _nicknameView.numberOfLines = 0;
        [_infoView addSubview:_nicknameView style:@"display: flex; font-size: 16px; color: #333333;"];
        
        _idView = [[UILabel alloc] init];
        [_infoView addSubview:_idView style:@"display: flex; margin-top: 5px; font-size: 14px; color: #666666; "];
    }
    return _infoView;
}

/// 加载数据
- (void)loadData {
    [self.avatarView setImageUrl:@"https://wx4.sinaimg.cn/orj360/007HbL0Agy1hw485pjninj32c0340u0x.jpg"];
    self.nicknameView.text = @"无名指的等待";
    self.idView.text = @"ID: 9090950";
    
}


@end
